package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingItemDto;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import com.zzyl.vo.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@Api(tags = "护理项目")
@RequestMapping("/nursing_project")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("护理项目分页查询")
    public ResponseResult<PageVo> getNursingProjectList(NursingProjectDto nursingDto) {
        PageResponse<NursingProjectVo> page = nursingProjectService.getNursingProjectList(nursingDto);
        return ResponseResult.success(page);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(
            @ApiParam(value = "护理项目数据传输对象", required = true)
            @RequestBody NursingItemDto nursingItemDto) {
        nursingProjectService.addNursingProject(nursingItemDto);
        return ResponseResult.success();
    }

    @GetMapping("{id}")
    @ApiOperation("查询回显")
    public ResponseResult<NursingProjectVo> getNursingProjectById(@PathVariable("id") Long id){
        NursingProjectVo nursingProjectVo= nursingProjectService.getNursingProjectById(id);
        return ResponseResult.success(nursingProjectVo);
    }

    @PutMapping
    @ApiOperation("修改护理项目")
    public ResponseResult updateNursingProject(@RequestBody NursingItemDto nursingItemDto){
        nursingProjectService.updateNursingProject(nursingItemDto);
        return ResponseResult.success();
    }

    @DeleteMapping("{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable("id") Long id){
        nursingProjectService.deleteNursingProject(id);
        return ResponseResult.success();
    }

    @PutMapping("{id}/status/{status}")
    @ApiOperation("护理项目启用禁用")
    public ResponseResult updateNursingProjectStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        nursingProjectService.updateNursingProjectStatus(id,status);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAllNursingProject(){
        List<NursingProjectVo> nursingProjectVoList = nursingProjectService.getAllNursingProject();
        return ResponseResult.success(nursingProjectVoList);
    }

}
